package com.feng.ioc.configuration;

import com.feng.ioc.condition.LinuxCondition;
import com.feng.ioc.condition.Windowscondition;
import com.feng.ioc.dao.BookDao;
import com.feng.ioc.bean.Color;
import com.feng.ioc.pojo.Person;
import com.feng.ioc.pojo.LoL;
import com.feng.ioc.pojo.World;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
//导入外部文件
@PropertySource( value = {"classpath:/info.properties"})
@Configuration
@ComponentScan(value = "com.feng" ,includeFilters = {
        //指定注解类型
        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class}),
        //指定给定的类型
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {BookDao.class,World.class, LoL.class}),
        //自定义类型 使用自己写的类 实现FilterType接口
        @ComponentScan.Filter(type = FilterType.CUSTOM,classes = {MyTypeFilter.class})
},useDefaultFilters = false)

@Import({Color.class, MyImportSelector.class,MyImportBeanDefinitionRegistrar.class,Init_Des_Config.class, World.class})

public class MainConfiguration {

//    prototype "原型模式" singleton "单例模式 默认的"  SCOPE_REQUEST "request 同一个请求创建一个实例" SCOPE_SESSION "session 同一个session创建一个实例"
    @Scope("prototype")
    @Bean("person")
    public Person person(){
        return  new Person();
    }

    @Scope("singleton")
    @Bean("person2")
    public Person person2(){
        return  new Person();
    }

//    @Primary
    @Lazy
    @Bean("person3")
    public Person person3(){
        return  new Person();
    }

    @Conditional({Windowscondition.class})
    @Bean("bill")
    public  Person person4(){
        return  new Person("windows");
    }

    @Conditional({LinuxCondition.class})
    @Bean("linus")
    public Person person5(){
        return  new Person("linux");
    }

    @Bean( )
    public MyFactoryBean person6(){
        return  new MyFactoryBean();
    }

    //此处参数可以不用显式声明@Autowired 自动从容器中取出与参数名一致的bean (在没有@Parmary的情况下)
    @Bean
    public World world( Person person){
        return new World(person);
    }


}
